package com.zr.controller;

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.zr.model.UserModel;
import com.zr.service.MangerSelectService;

/**
 * 添加学生信息控制
 * @author wxz
 * 2016年5月24日下午4:58:39
 */
public class GetMangerAppendController extends HttpServlet{
	MangerSelectService sss = new MangerSelectService();
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doPost(req, resp);
	}
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		//将接收到的数据封装到UserModel中
		UserModel user = new UserModel();
		req.setCharacterEncoding("utf8");
		String appendSid=req.getParameter("sid");
		String appendSname=req.getParameter("sname");
		String appendSage=req.getParameter("sage");
		String appendSsex=req.getParameter("ssex");
		String appendScollege=req.getParameter("scollege");
		String appendSaddress=req.getParameter("saddress");
		String appendSphone=req.getParameter("sphone");
		
		// 判断前台输入的账号如果不为空，则将String转换为int
	 
			try {
					user.setSid(Integer.parseInt(appendSid));
					user.setSage(Integer.parseInt(appendSage));
			} catch (NumberFormatException e) {
				// TODO: handle exception
				e.printStackTrace();
			}
	  
		user.setSname(appendSname);
		user.setSsex(appendSsex);
		user.setScollege(appendScollege);
		user.setSaddress(appendSaddress);
		user.setSphone(appendSphone);
		user.setSpwt(appendSid);
		boolean flag=sss.getStudentAppend(user);
		resp.setCharacterEncoding("utf8");
		PrintWriter pw=resp.getWriter();
		if(flag){
			pw.write("添加成功");
		}
		
	}
}
